package mess;

import java.util.Arrays;

public class LeeCode_1599 {
    public static void main(String[] args) {
        //System.out.println(minOperationsMaxProfit(new int[]{8, 3}, 5, 6));
        System.out.println(minOperationsMaxProfit(new int[]{10, 9, 6}, 6, 4));
    }

    private static int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {
        int res = 0;
        int[] max = new int[2];
        int len = customers.length;
        int up = 0;
        int wait = 0;
        int i = 0;
        int cost = runningCost;
        int times = 0;
        while(i < len ||wait > 0){
            int count = 0;
            if(i < len)
                count = customers[i];
            up += Math.min((count + wait), 4);
            wait += count > 4 ? count - 4 : ((count + wait) > 4 ? -(4 - count) : -wait);
            res = up * boardingCost - cost;
            //System.out.println(up+"*"+boardingCost+"-"+cost);
            //System.out.println(res);
            if(i < len)
                i++;
            times++;
            if(res > max[0]){
                max[0] = res;
                max[1] = times;
            }
            cost += runningCost;
        }
        System.out.println(Arrays.toString(max));
        if(max[0] > 0)
            return max[1];
        else
            return -1;
    }
}
